/* Copyright(c) 2010- Siro-info Co.(http://www.siro-info.com)
 * All rights reserved.
 */
package com.siro.pm.ui.view;

import com.siro.pm.model.provider.AttendanceTreeProvider;
import com.siro.pm.ui.main.AttendancePage;
import com.siro.pm.ui.main.InvoicePage;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Component;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Tree;

/**
 * Class Declaration:
 * 
 * @version v1.0
 * @since AttendanceView.java v1.0
 */
public class AttendanceView extends HorizontalSplitPanel {
	private static final long serialVersionUID = 5107308900359674025L;

	public AttendanceView() {
		super();
	}

	public void createContents() {
		setSizeFull();
		setSplitPosition(20, Sizeable.UNITS_PERCENTAGE);
		// Menu tree, initially shown
		CssLayout menuLayout = new CssLayout();
		menuLayout.addComponent(createMenuTree());
		setFirstComponent(menuLayout);
	}

	private Component createMenuTree() {
		final Tree menuTree = new Tree();
		menuTree.setImmediate(true);
		menuTree.setStyleName("menu");
		menuTree.setContainerDataSource(AttendanceTreeProvider
				.getAttendanceTreeContainer());
		menuTree.setItemCaptionPropertyId(AttendanceTreeProvider.ATTENDANCE_PROPERTY_NAME);
		menuTree.setItemIconPropertyId(AttendanceTreeProvider.ATTENDANCE_PROPERTY_ICON);
		menuTree.addListener(new ValueChangeListener() {
			private static final long serialVersionUID = 1L;

			public void valueChange(ValueChangeEvent event) {
				Object value = event.getProperty().getValue();
				if (value != null) {
					if (value
							.equals(AttendanceTreeProvider.ATTENDANCE_ITEM_INVOICE)) {
						InvoicePage invoicePage = new InvoicePage();
						invoicePage.createContents();
						setSecondComponent(invoicePage);
					} else if (value
							.equals(AttendanceTreeProvider.ATTENDANCE_ITEM_ATTENDANCE)) {
						AttendancePage calendarPage = new AttendancePage();
						calendarPage.createContents();
						setSecondComponent(calendarPage);
					}
				}
			}
		});
		return menuTree;
	}

}
